package com.xiaoxiao.springbootstudy.controller;


import com.xiaoxiao.springbootstudy.pojo.OutStore;
import com.xiaoxiao.springbootstudy.service.OutStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@CrossOrigin
@RestController
public class OutStoreController {
    @Autowired
    OutStoreService outStoreService;

    @PostMapping("/doItemOutStore")
    public Map<String, Object> doItemOutStore(@RequestBody OutStore outStore) {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("msg", "出库失败");

        try {
            outStoreService.saveOutStoreService(outStore);
            result.put("code", 200);
            result.put("msg", "出库成功");
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    @GetMapping("/getOutStoreList")
    public Map<String, Object> getOutStoreList(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        return outStoreService.queryOutStoreListMapper(pageNum, pageSize);
    }

    @GetMapping("/updateOutStore")
    public Map<String, Object> updateOutStore(Integer id) {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 400);
        result.put("msg", "操作失败");
        try {
            OutStore os = new OutStore();
            os.setOutsId(id);
            os.setIsOut("1");
            outStoreService.updateById(os);
            result.put("code", 200);
            result.put("msg", "出库单确认成功");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return result;
    }
}
